/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.schedule.core.service.processor.edit;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.component.schedule.core.domain.ScheduleNode;
import info.peigen.hotpot.component.schedule.core.service.processor.AbstractScheduleServiceProcessor;
import info.peigen.hotpot.component.schedule.facade.command.order.ScheduleNodeEditOrder;
import org.noear.solon.annotation.Component;

/**
 * <b>(ScheduleNodeEditProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/7
 */
@Component
public class ScheduleNodeEditProcessor extends AbstractScheduleServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 20;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        ScheduleNodeEditOrder editOrder    = (ScheduleNodeEditOrder) serviceContext.getOrder();
        ScheduleNode          scheduleNode = (ScheduleNode) serviceContext.getDomain();
        if (StrUtil.isNotBlank(editOrder.getNodeName())) {
            scheduleNode.setNodeName(editOrder.getNodeName());
        }

        if (StrUtil.isNotBlank(editOrder.getCron())) {
            scheduleNode.setCron(editOrder.getCron());
        }

        if (ObjUtil.isNotNull(editOrder.getEnable())) {
            scheduleNode.setYesOrNo(editOrder.getEnable());
        }

        if (StrUtil.isNotBlank(editOrder.getMemo())) {
            scheduleNode.setMemo(editOrder.getMemo());
        }
    }
}